package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.Water;
import com.ruoyi.system.service.IWaterService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 水滴记录Controller
 * 
 * @author ruoyi
 * @date 2025-02-19
 */
@RestController
@RequestMapping("/water")
public class WaterController extends BaseController
{
    @Autowired
    private IWaterService waterService;

    /**
     * 查询水滴记录列表
     */
    @RequiresPermissions("system:water:list")
    @GetMapping("/list")
    public TableDataInfo list(Water water)
    {
        startPage();
        List<Water> list = waterService.selectWaterList(water);
        return getDataTable(list);
    }

    /**
     * 导出水滴记录列表
     */
    @RequiresPermissions("system:water:export")
    @Log(title = "水滴记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Water water)
    {
        List<Water> list = waterService.selectWaterList(water);
        ExcelUtil<Water> util = new ExcelUtil<Water>(Water.class);
        util.exportExcel(response, list, "水滴记录数据");
    }

    /**
     * 获取水滴记录详细信息
     */
    @RequiresPermissions("system:water:query")
    @GetMapping(value = "/{waterId}")
    public AjaxResult getInfo(@PathVariable("waterId") Long waterId)
    {
        return success(waterService.selectWaterByWaterId(waterId));
    }

    /**
     * 新增水滴记录
     */
    @RequiresPermissions("system:water:add")
    @Log(title = "水滴记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Water water)
    {
        return toAjax(waterService.insertWater(water));
    }

    /**
     * 修改水滴记录
     */
    @RequiresPermissions("system:water:edit")
    @Log(title = "水滴记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Water water)
    {
        return toAjax(waterService.updateWater(water));
    }

    /**
     * 删除水滴记录
     */
    @RequiresPermissions("system:water:remove")
    @Log(title = "水滴记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{waterIds}")
    public AjaxResult remove(@PathVariable Long[] waterIds)
    {
        return toAjax(waterService.deleteWaterByWaterIds(waterIds));
    }
}
